package com.record.controller;

import com.record.dto.*;
import com.record.entity.Formula;
import com.record.service.TasteService;
import com.record.utils.Result;
import com.record.vo.FangjiKeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.record.utils.Empties.impty;

@Api(tags = "查询功效")
@RestController
public class TasteController {

    @Autowired
    private TasteService tasteService;

    /**
     * 通过方剂名查询完整信息（组方+剂量+功效）
     * 访问示例: http://localhost:8888/getTasteName
     */
    @ApiOperation(value = "根据组方查询含有几个味道（）")
    @GetMapping("/getTasteName")
    public Result getTasteName(@RequestParam String TasteName) {
        FormulaSixDto formulaSixDto = tasteService.getTasteName(TasteName);
        if (formulaSixDto == null) {
            return Result.fail("未找到该组方的味道");
        }
        return Result.success(formulaSixDto);
    }


    /**
     * 根据所给的味道给出所有的权重
     */
    @ApiOperation(value = "根据组方查询权重")
    @GetMapping("/getWeight")
    public Result getWeight(@RequestParam String Zufang) {
        List<IndexedValue> indexedValue = tasteService.getWeight(Zufang);
        if (indexedValue == null) {
            return Result.fail("未找到该组方的权重");
        }
        return Result.success(indexedValue);
    }


    @ApiOperation(value = "根据组方查询其总量")
    @GetMapping("/getTotallyWeight")
    public Result getTotallyWeight(@RequestParam String Zufang) {
        TotalWeightDto totalWeightDto = tasteService.getTotallyWeight(Zufang);
        if (totalWeightDto == null) {
            return Result.fail("未找到该组方的权重");
        }
        return Result.success(totalWeightDto);
    }


    @ApiOperation(value = "根据方剂查询其总量")
    @GetMapping("/getFangjiWeight")
    public Result getFangjiWeight(@RequestParam String Fangji) {
        FangjiWeightDto fangjiWeightDto = tasteService.getFangjiWeight(Fangji);
        if (fangjiWeightDto == null) {
            return Result.fail("未找到该方剂总的权重");
        }
        return Result.success(fangjiWeightDto);
    }


    /**
     * 根据方剂查询其总的组方在某一味的权重
     */
    @ApiOperation(value = "根据方剂查询其总的组方在某一味的权重")
    @GetMapping("/getFangjike")
    public Result getFangjike(@RequestParam String fangjiKeVo) {
        FangjiKeDto fangjiKeDto = tasteService.getFangjike(fangjiKeVo);
        if (fangjiKeDto == null) {
            return Result.fail("未找到方剂中在某味道的克数");
        }
        return Result.success(fangjiKeDto);
    }
























}
